package day019.ioStream;

import java.io.*;

public class BufferedStreamDemo2 {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        method4();

        long endTime = System.currentTimeMillis();
        System.out.println("花费的时间为：" + (endTime - startTime) + "毫秒");
    }

    private static void method1() {
        try (
                FileInputStream fis = new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\dog.jpg");
                FileOutputStream fos = new FileOutputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\test6.jpg");
        ) {
            int by;
            while ((by = fis.read()) != -1) {
                fos.write(by);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void method2() {
        try (
                FileInputStream fis = new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\dog.jpg");
                FileOutputStream fos = new FileOutputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\test6.jpg");
        ) {
            byte[] bys = new byte[1024];
            int len;
            while ((len = fis.read(bys)) != -1) {
                fos.write(bys, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void method3() {
        try (
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\dog.jpg"));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\test6.jpg"));
        ) {
            int by;
            while ((by = bis.read()) != -1) {
                bos.write(by);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void method4() {
        try (
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\dog.jpg"));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\ideaProjects\\javase_code\\study-practice\\" +
                        "src\\day019\\ioStream\\day019_demo\\test6.jpg"));
        ) {
            byte[] bys = new byte[1024];
            int len;
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
